<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>宝宝信息</title>
		<meta name="description" content="">
		<meta name="keywords" content="">
		<meta name="renderer" content="webkit">
		<!-- 设置缩放 -->
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui" />
		<!-- 可隐藏地址栏，仅针对IOS的Safari（注：IOS7.0版本以后，safari上已看不到效果） -->
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<!-- 仅针对IOS的Safari顶端状态条的样式（可选default/black/black-translucent ） -->
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
		<meta name="format-detection" content="telephone=no, email=no" />
		<!-- 启用360浏览器的极速模式(webkit) -->
		<meta name="renderer" content="webkit">
		<!-- 避免IE使用兼容模式 -->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
		<meta name="HandheldFriendly" content="true">
		<!-- 微软的老式浏览器 -->
		<meta name="MobileOptimized" content="320">
		<!-- uc强制竖屏 -->
		<meta name="screen-orientation" content="portrait">
		<!-- QQ强制竖屏 -->
		<meta name="x5-orientation" content="portrait">
		<!-- UC强制全屏 -->
		<meta name="full-screen" content="yes">
		<!-- QQ强制全屏 -->
		<meta name="x5-fullscreen" content="true">
		<!-- UC应用模式 -->
		<meta name="browsermode" content="application">
		<!-- QQ应用模式 -->
		<meta name="x5-page-mode" content="app">
		<!-- windows phone 点击无高光 -->
		<meta name="msapplication-tap-highlight" content="no">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="icon" type="image/png" href="../assets/i/favicon.png">
		<link rel="stylesheet" href="../assets/choice/iosSelect.css">
		<link rel="stylesheet" href="../assets/css/LArea.css">
		<link rel="stylesheet" href="../assets/css/amazeui.css" />
		<link rel="stylesheet" href="../css/comm.css" />
		<link rel="stylesheet" href="../css/childrenForm.css" />
		<style>
			.am-icon-md:before {
			    font-size: 100%;
			    vertical-align: 0%;
			}
		</style>
	</head>
	<body >
		<header data-am-widget="header" class="am-header am-header-default bg-48CFAE">
			<div class="am-header-left am-header-nav text-black padding-left05" id="goBackDivs">
				<a  href="javascript:history.go(-1)" class="text-black" id="goBackIcon">
				  	<i class="am-align-left am-margin-0 am-icon-angle-left am-icon-md text-black co-fff"></i>
				  </a> 
			</div>
			<h1 class="am-header-title teblack">
				<a href="#title-link" class="co-fff" id="courseName">宝宝信息</a>
			</h1>
			<div class="am-header-right am-header-nav">
	          <a href="javascript:void(0)" title="" id="complet" >完成</a>
	      	</div>
		</header>
	  <div class="content">
		 <div class="form-list">
		 	<ul class="am-list xing">
			</ul>
		 </div>
	  </div>

	<div class="am-modal am-modal-alert" tabindex="-1" id="ceng">
		<div class="am-modal-dialog" style="border-radius: 10px;">
			<div class="am-modal-bd" id="info-text"></div>
		</div>
	</div>

	  <div class="am-modal am-modal-loading am-modal-no-btn radius4" tabindex="-1" id="my-modal-loading" data-am-modal="{closeViaDimmer: 0}">
			  <div class="am-modal-dialog" style="border-radius: 4px;">
			    	<div class="am-modal-hd">加载中...</div>
				    <div class="am-modal-bd">
				      <span class="am-icon-spinner am-icon-spin"></span>
				    </div>
			  </div>
		</div>
		<script src="../assets/js/jquery.min.js"></script>
		<script src="../assets/js/jquery.cookie.js"></script>
		<script src="../assets/js/amazeui.min.js"></script>
		<script src="../assets/choice/iosSelect.js"></script>
		<script src="../assets/js/datePicker.js"></script>
		<script src="../assets/js/LAreaData2.js"></script>
		<script src="../assets/js/LArea.js"></script>
		<script src="../js/ym.js"></script>
		<script src="../js/childForm.js"></script>
		<script>
			var curData=JSON.parse(sessionStorage.getItem('curData'));
			 /* 上传头像 预览 */
	        function preview(file) {
	            var prevDiv = document.getElementById('preview');
	            if (file.files && file.files[0]) {
	                var reader = new FileReader();
	                reader.onload = function(evt){
	                    prevDiv.innerHTML = '<img class="touxiang" src="' + evt.target.result + '" />';
	                }
	                reader.readAsDataURL(file.files[0]);
	            } else {
	                prevDiv.innerHTML = '<div style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
	            }
	           	imgUpload(file.files[0]);
	        }
	        function imgUpload(file){
	        	$("#my-modal-loading").modal('open');
                var formData=new FormData();
                formData.append("imageFile",file);
                formData.append("relevanceId",curData.childId);
    			formData.append("relevanceTpyeId",4);
                $.ajax({
	                url: "/web/uploadUserHeader",
                    type : "post",
                    processData : false,
                    contentType : false,
                    data:formData,
                    success : function(data) {
	                    imgurl=data.obj.imagePath;
	                    $('.touxiang').attr('src',imgurl);
						ym.ajax({
                            url: "/userChild/updateUserChild",
							param : {
                                childId : curData.childId,
                                childHeadimgurl : imgurl
							},
                            success : function(data){
                            	$("#my-modal-loading").modal('close');
                                $('#ceng').modal('open');
                                $('#info-text').html('修改成功！');
                                window.setTimeout(function(){
                                    $('#ceng').modal('close');
                                },500)
							}
						})
	                },
	                error: function (data) {
	                    console.log(data);
	                }
	            });
	        }
			$(function(){
				var mydata = new Date();
				var years = mydata.getFullYear();
				var months = mydata.getMonth()+1;
				var days = mydata.getDate();
				var place=[];
				var time = years +"-"+months+"-"+days;
				var theSelectData="";
				var charector="";
				var gender="1";
				var phone="";
				var addr="";
				var jzAddr="";
				var provs_data=[];
				var area2 = new LArea();
				var genderHTMl="";
				if(curData.childSex=='1'){
				  genderHTMl+="<li>"+
			  	              "<a href='#'>"+
			  				  "<p>性别：</p>"+
			  				  "<p class='changeGender'>"+
			  			      "<label class='am-radio boy select' style='color:#46c8ff'>"+
			  			  	  "<span><img src='./../img/boy1.png' alt=''></span>"+
					      	  "<input type='radio' name='radio1' value='' data-am-ucheck checked>"+
					      	  "男"+
					    	  "</label>"+
					    	  "<label class='am-radio girl'>"+
					          "<span><img src='./../img/girl.png' alt=''></span>"+
					          "<input type='radio' name='radio1' value='' data-am-ucheck>"+
					          "女"+
					          "</label>"+
			  		          "</p>"+
			  	              "</a>"+
			                  "</li>";
				}else if(curData.childSex=='2'){
					genderHTMl+="<li>"+
			  	              "<a href='#'>"+
			  				  "<p>性别：</p>"+
			  				  "<p class='changeGender'>"+
			  			      "<label class='am-radio boy select'>"+
			  			  	  "<span><img src='./../img/boy.png' alt=''></span>"+
					      	  "<input type='radio' name='radio1' value='' data-am-ucheck >"+
					      	  "男"+
					    	  "</label>"+
					    	  "<label class='am-radio girl' style='color:#46c8ff'>"+
					          "<span><img src='./../img/girl1.png' alt=''></span>"+
					          "<input type='radio' name='radio1' value='' data-am-ucheck checked>"+
					          "女"+
					          "</label>"+
			  		          "</p>"+
			  	              "</a>"+
			                  "</li>";
				}
				if(curData.vaccineStationName == null){
					curData.vaccineStationName = "";
				}
				var childHTML="<li class='am-text-center'>"+
			  	              "<a href='#' class='am-text-center'>"+
			  				  "<form enctype='multipart/form-data' class='w100 am-margin-bottom-lg'>"+
			  				  "<div class='headerdivs'>"+
							  "<div id='preview'>"+
							  "<img src='"+curData.childHeadimgurl+"'/>"+
							  "</div>"+
							  "<p class='am-margin-top-sm colorfd91'>更改头像</p>"+
							  "<input type='file' onchange='preview(this)' id='file'/>"+
							  "</div>"+
			  				  "</form>"+
			  				  "</a>"+
			  				  "</li>"+
			  				  "<li>"+
			  	              "<a href='#'>"+
			  		          "<p>姓名：<input type='text' class='childName' style='border: none;outline: none;' value='"+curData.childRealname+"'/>"+genderHTMl+"</p>"+
			  				  	
			  				  "</a>"+
			  				  "</li></ul>"+
		                      "</div>"+
		     				  "<div class='form-list'>"+
		 					  "<ul class='am-list'>"+
			  				  "<li>"+
			  				  "<a href='javascript:void(0)'>"+
			  				  "<p>出生日期："+
			  				  "<input required readonly type='text' id='childuserBirthday' placeholder='"+curData.childBirthday+"' style='border: none;outline: none;'/>"+
			  				  "</p>"+
			  				  "</a>"+
			  				  "</li>"+
			  				  "<li>"+
			  	    		  "<a href='#'>"+
			  				  "<p>我的编码：<input type='text' class='childCode' style='border: none;outline: none;' value='"+curData.childCode+"'/></p>"+
			  				  "<p></p>"+
			  	    		  "</a>"+
			        		  "</li>"+
			        		  "<li>"+
			  	    		  "<a href='#'>"+
			  				  "<p>接种单位："+
			  				  	"<input readonly id='address' placeholder='"+curData.vaccineStationName+"' style='border: none;outline: none;'/>"+
							  "<input id='value2' type='hidden'/>"+
                    			"</p>"+
			  	    		  "</a>"+
			        		  "</li>";
			    $('.am-list').html(childHTML);
				/*宝宝生日*/
				var calendar = new datePicker();
				calendar.init({
					'trigger': '#childuserBirthday', /*按钮选择器，用于触发弹出插件*/
					'type': 'date',/*模式：date日期；datetime日期时间；time时间；ym年月；*/
					'minDate':'1995-1-1',/*最小日期*/
					'maxDate':time,/*最大日期*/
					'onSubmit':function(){/*确认时触发事件*/
						theSelectData=calendar.value;
					},
					'onClose':function(){/*取消时触发事件*/
					}
				});
				
				
				/*性别点击事件*/
				var body = '<img src="../img/boy.png"><span>男</span>'
				var body1 = '<img src="../img/boy1.png"><span>男</span>'
				var girl = '<img src="../img/girl.png"><span>女</span>'
				var girl1 = '<img src="../img/girl1.png"><span>女</span>'
				if(curData.childSex=='1'){
					$('.boy').html(body1);
					$('.boy').css('color','#46c8ff');
					$('.boy').addClass("select");
					$('.boy').next().removeClass("select");
					$('.boy').next().html(girl);
					$('.boy').next().css('color','#999999');
					gender="1";
				}else if(curData.childSex=='2'){
					$('.girl').html(girl1);
					$('.girl').css('color','#46c8ff');
					$('.girl').addClass("select");
					$('.girl').prev().removeClass("select");
					$('.girl').prev().html(body);
					$('.girl').prev().css('color','#999999');
					gender='2';	
				}	
				$('.boy').on('click',function(){
					$(this).html(body1);
					$(this).css('color','#46c8ff');
					$(this).addClass("select");
					$(this).next().removeClass("select");
					$(this).next().html(girl);
					$(this).next().css('color','#999999');
					gender="1";
					var dataJson={
								childSex:gender,
								childId:curData.childId
							}
							ym.ajax({
										url: "/userChild/updateUserChild",
										param:dataJson,
										success: function (data) {
											console.log(dataJson)
										}
								});
				})
				$('.girl').on('click',function(){
					$(this).html(girl1);
					$(this).css('color','#46c8ff');
					$(this).addClass("select");
					$(this).prev().removeClass("select");
					$(this).prev().html(body);
					$(this).prev().css('color','#999999');
					gender='2';
					var dataJson={
								childSex:gender,
								childId:curData.childId
							}
							ym.ajax({
										url: "/userChild/updateUserChild",
										param:dataJson,
										success: function (data) {
											console.log(dataJson)
										}
								});
				})	
					ym.ajax({
						url: "/areaController/queryTree",
						success: function (data) {
							if(data.obj){
								provs_data=data.obj;		
				 			}
							area2.init({
									'trigger': '#address',
									'valueTo': '#value2',
									'keys': {
											id: 'id',
											name: 'name'
									},
									'type': 1,
									'data':provs_data
							});
						}
					})
					//接种所在地
					var address=document.querySelector('#address');
					address.addEventListener('blur', function () {
							var provinceCode=localStorage.getItem('provinceCode');
							var cityCode=localStorage.getItem('cityCode');
							var countyCode=localStorage.getItem('countyCode');
							addr=address.value;
							var data={};
							console.log(provinceCode,cityCode,countyCode)
							if(countyCode!=='null'){
								data={ countyAreaId:countyCode };
							}else if(countyCode==='null'&&cityCode!=='null'){
								data={ cityAreaId:cityCode };
							}else{
								data={ provinceAreaId:provinceCode };
							}
							/*查询地级市下面的接种点*/
							ym.ajax({
									url: "/areaController/getStationDto",
									param:data,
									success: function (data) {
										if(data.obj){
												place=[];
												for (var i = 0; i < data.obj.length; i++) {
													place.push({id:data.obj[i].station_id,value:data.obj[i].station_name});
												}
										}
									}
								});
							if(place.length!==0){
									var bankSelect = new IosSelect(1, 
											[place],
											{
													container: '.container',
													title: '接种地点',
													callback: function (selectOneObj) {
															$("#address").val(selectOneObj.value);
															jzAddr=selectOneObj.id;
															if(localStorage.getItem('countyCode')=='null'){
																var dataJson={
																		provinceAreaId:localStorage.getItem('provinceCode'),
															    		cityAreaId:localStorage.getItem('cityCode'),
																		vaccineStationId:jzAddr,
																		childId:curData.childId
																	}
																}else{
																	var dataJson={
																		provinceAreaId:localStorage.getItem('provinceCode'),
															    		cityAreaId:localStorage.getItem('cityCode'),
															    		countyAreaId:localStorage.getItem('countyCode'),
																		vaccineStationId:jzAddr,
																		childId:curData.childId
																	}
																}
														ym.ajax({
																	url: "/userChild/updateUserChild",
																	param:dataJson,
																	success: function (data) {
																		console.log(dataJson)
																	}
															});
													},
													fallback: function () {
															console.log(1);
													},
													maskCallback: function () {
															console.log(2);
													}
									});
							}
						});
					/* 修改名字 */
					var editName=document.querySelector('.childName');
					editName.addEventListener('blur', function () {
                        if(editName.value == '' || editName.value==null || editName.value==undefined){
                            $("#my-modal-loading").modal('close');
                            $('#ceng').modal('open');
                            $('#info-text').html('姓名不能修改为空哦！');
                            window.setTimeout(function(){
                                $('#ceng').modal('close');
                            },500)
							$('.childName').val(curData.childRealname);
                        }else {
                            var dataJson={
                                childRealname:editName.value,
                                childId:curData.childId
                            }
                            ym.ajax({
                                url: "/userChild/updateUserChild",
                                param:dataJson,
                                success: function (data) {
                                    $('#ceng').modal('open');
                                    $('#info-text').html('修改成功！');
                                    window.setTimeout(function(){
                                        $('#ceng').modal('close');
                                    },500)
                                }
                            });
						}
					})


                /* 修改编码 */
                var editCode=document.querySelector('.childCode');
                editCode.addEventListener('blur', function () {
                    var dataJson={
                        childCode:editCode.value,
                        childId:curData.childId
                    }
                    ym.ajax({
                        url: "/userChild/updateUserChild",
                        param:dataJson,
                        success: function (data) {

                        }
                    });
                })

					/*修改生日*/
					var editBirth=document.querySelector('#childuserBirthday');
					editBirth.addEventListener('blur', function () {
						var dataJson={
							childBirthday:editBirth.value,
							childId:curData.childId
						}
						ym.ajax({
									url: "/userChild/updateUserChild",
									param:dataJson,
									success: function (data) {
										console.log(dataJson)
									}
							});
					})
				
				$('#complet').on('click',function(){
					window.location.href="myBaby.html";
				})

			})
		</script>
	</body>
</html>
